﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Services;
using Public;

namespace WebsiteAdmin.DataProtec.Handler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class EncryptDecrypt : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string ResultStr = "";
            if (Cookie.AdminLoginName != null || Cookie.AdminLoginName != "")
            {
                int Flag = Convert.ToInt16(context.Request["reg"].ToString());
                string str = context.Request["str"].ToString();

                if (Flag == 1)//加密
                {
                    if (str != null && str != "")
                    {
                        ResultStr = Public.DataProtector.EncryptString(str);//通过公共类方法进行加密
                    }
                }
                else if (Flag == 2)//解密
                {
                    if (str != null && str != "")
                    {
                        ResultStr = Public.DataProtector.DecryptString(str);
                    }
                }
            }
            context.Response.Write(ResultStr);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
